package com.nexgo.payment.action.online.upload;

import com.nexgo.payment.databases.DataSource;
import com.nexgo.payment.databases.Signature;

import java.util.ArrayList;
import java.util.List;

import java8.util.Optional;

/**
 * Created by xiaox on 2017/9/15.
 */

class UploadEsOnlineLastButNotCurrent extends AbsUploadEs {
    UploadEsOnlineLastButNotCurrent(DataSource repository) {
        super(repository);
    }

    @Override
    List<Signature> getUploadSignatures() {
        return Optional.ofNullable(mRepository.getLastSuccessfulTransRecord())
                .map(transRecord -> mRepository.getLastOnlineButNotCurrentSignature(transRecord.getTraceNum()))
                .map(signature -> {
                    ArrayList<Signature> signatures = new ArrayList<>();
                    signatures.add(signature);
                    return signatures;
                }).get();
    }
}
